import os
from flaskr import create_app
from dotenv import load_dotenv, find_dotenv
from flaskr.error import InvalidUsage
from flask import make_response

load_dotenv(find_dotenv())
env_name = os.getenv('FLASK_ENV')
app = create_app(env_name)


@app.errorhandler(InvalidUsage)
def invalid_usage(error):
    response = make_response(error.message)
    response.status_code = error.status_code
    return response


if __name__ == "__main__":
    port = os.getenv('PORT')
    app.run(host="0.0.0.0", port=port)
